{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <input type="hidden" name="id" value="{$article.id}">
                <div class="layui-row  layui-form-item">
                    <label class="layui-form-label">标题：</label>
                    <div class="layui-input-block">
                        <input type="text" name="username" autocomplete="off" class="layui-input" value="{$article.username}" lay-verify="required">
                    </div>
                </div>
                <div class="layui-row  layui-form-item">
                    <label class="layui-form-label">所属角色：</label>
                    <div class="layui-inline">
                        <select name="role_id" id="role_id" lay-filter="role_id">
                            {volist name="role" id="vo"}
                            <option value="{$vo.id}" {eq name="vo.id" value="$article['role_id']" }selected{/eq}>{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-row  layui-form-item">
                    <label class="layui-form-label">手机：</label>
                    <div class="layui-inline">
                        <input type="text" name="phone" value="{$article.phone}" autocomplete="off" class="layui-input" lay-verify="phone">
                    </div>
                </div>
                <div class="layui-row  layui-form-item">
                    <label class="layui-form-label">qq：</label>
                    <div class="layui-inline">
                        <input type="text" name="qq" value="{$article.qq}" autocomplete="off" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-row  layui-form-item">
                    <label class="layui-form-label">邮箱：</label>
                    <div class="layui-inline">
                        <input type="text" name="email" value="{$article.email}" autocomplete="off" class="layui-input" lay-verify="required|email" >
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="btnSave">保存</button>
                            <a class="layui-btn layui-btn-primary" href="javascript:parent.location.reload();">返回</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>

    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: '/lib/index' //主入口模块
    }).use(['index', 'table', 'jquery', 'layer', 'form'], function () {
        var $ = layui.$, form = layui.form;



        form.on('select(departID)', function (data) {
            $.post("{:url('getTeam')}", {id: data.value}, function (res) {
                var data = res['data'];
                $('#teamID').empty();
                if (res['code'] == 0) {
                    for (i = 0; i < data.length; i++) {
                        $('#teamID').append('<option value="' + data[i]['id'] + '">' + data[i]['name'] + '</option>');
                    }
                } else {
                    $('#teamID').append('<option value="0" selected>选择团队</option>');
                }
                form.render("select");
            });
        });

        form.on('submit(btnSave)', function (data) {
            $.post("{:url('edit')}", data.field, function (result) {
                console.log(result);
                if (result['code'] == 0) {
                    layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(result['msg'], {icon: 3, time: 3000});
                }
            });

            return false;
        });
    });

</script>
{/block}